{extend name="public/base"/}
{block name="content"}
    <div class="data-list" data-url="{:url('index')}">
        <form class="layui-form inline-form">
            <div class="pull-left">
                <div class="layui-inline">
                    <select name="platform_id" lay-search lay-filter="data-list">
                        <option value="">全部</option>
                        {foreach $platform as $p}
                        <option value="{$p.platform_id}">{$p.name}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="layui-inline">
                    <input class="layui-input" autocomplete="off" name="name" placeholder="店铺或账号">
                </div>
                <div class="layui-inline">
                    <input class="layui-input laydate-range" autocomplete="off" name="date" placeholder="录入时间">
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-sm layui-btn-normal search"><i class="layui-icon layui-icon-search"></i></button>
                </div>
            </div>
            <div class="pull-right">
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-normal layui-btn-sm ajax-form" height-form="60%" data-url="{:url('add')}"><i class="layui-icon layui-icon-add-circle"></i> 新增</button>
                    <button class="layui-hide" id="render-site">
                        渲染站点
                        <span>{$country|json_encode}</span>
                    </button>
                </div>
            </div>
        </form>
        <div class="data">
            <p><i class="fa fa-spinner fa-spin"></i> 加载中...</p>
        </div>
    </div>
{/block}
{block name="script"}
<script type="text/javascript">
    layui.extend({
        xmSelect: 'xm-select'
    }).use(['layer', 'xmSelect'], function()
    {
        $("#render-site").click(function()
        {
            var $node = $("#site-xm-select");
            var xargs = {
                el: $node.get(0),
                prop: {
                    name: 'name_ch',
                    value: 'code_two',
                },
                name: $node.attr("name"),
                filterable: true,
            };
            var json = JSON.parse($(this).find("span").text())
                , value = $node.attr("value") || "";
            if(value.length > 0)
            {
                var sel = value.split(",").filter(e => {return e!="";});
                for(let i in  json)
                {
                    if($.inArray(json[i].code_two, sel) >= 0) json[i]["selected"] = true;
                }
            }
            xargs.data = json;
            layui.xmSelect.render(xargs);
            return false;
        });
    });
</script>
{/block}
